#!/bin/bash

. /home/$USER/valire-scripts/eclipse/$USER.env

function assertVariable {
	if [ -z "$2" ]
	then
		echo "$1 is undefined"
		exit 1
	fi
}

function assertDir {
	if [ ! -d $2 ]
	then
		echo "dir $1 is does not exist"
		exit 1
	fi
}

assertVariable "JAVA_HOME" $JAVA_HOME
assertDir "JAVA_HOME" $JAVA_HOME
assertVariable "ECLIPSE_DIR" $ECLIPSE_DIR
assertDir "ECLIPSE_DIR" $ECLIPSE_DIR
assertVariable "WORKSPACE_NAME" $WORKSPACE_NAME
assertVariable "WORKSPACES_DIR" $WORKSPACES_DIR
assertVariable "ECLIPSE_PLATF" $ECLIPSE_PLATF
assertVariable "WTP" $WTP
assertVariable "JEE_DIR" $JEE_DIR

echo WORKSPACES_DIR=$WORKSPACES_DIR
echo WORKSPACE_NAME=$WORKSPACE_NAME

export ICONS_DIR="/home/$USER/valire-scripts/eclipse/icons/$WORKSPACE_NAME"
export WORKSPACE_DIR="$WORKSPACES_DIR/$WORKSPACE_NAME"

if [ -d $ICONS_DIR ]
then
echo copying icons
cp $ICONS_DIR/splash.bmp $ECLIPSE_DIR/plugins/$ECLIPSE_PLATF
cp $ICONS_DIR/ide.gif $ECLIPSE_DIR/plugins/$ECLIPSE_PLATF/eclipse.gif
cp $ICONS_DIR/ide.gif $ECLIPSE_DIR/plugins/$ECLIPSE_PLATF/eclipse.png
cp $ICONS_DIR/ide.gif $ECLIPSE_DIR/plugins/$ECLIPSE_PLATF/eclipse32.gif
cp $ICONS_DIR/ide.gif $ECLIPSE_DIR/plugins/$ECLIPSE_PLATF/eclipse48.gif
cp $ICONS_DIR/ide.gif $ECLIPSE_DIR/plugins/$ECLIPSE_PLATF/eclipse32.png
cp $ICONS_DIR/ide.gif $ECLIPSE_DIR/plugins/$ECLIPSE_PLATF/eclipse48.png
cp $ICONS_DIR/ide.gif $ECLIPSE_DIR/plugins/$JEE_DIR/javaee-ide_x16.png
cp $ICONS_DIR/ide.gif $ECLIPSE_DIR/plugins/$JEE_DIR/javaee-ide_x32.png
cp $ICONS_DIR/ide.gif $ECLIPSE_DIR/plugins/$JEE_DIR/javaee-ide_x48.png
fi

export ECLIPSE_CMD="$ECLIPSE_DIR/eclipse -Xmx512m -vm $JAVA_HOME/bin/java -data $WORKSPACE_DIR"

